#ifndef USERCONFIRMFILTER_H
#define USERCONFIRMFILTER_H

#include <mutex>

#include "config.h"
#include "filter.h"
#include "lru_cache.h"

class BlockTypeDetector {
public:
    explicit BlockTypeDetector(const std::vector<AppInfo> &appList, const std::map<std::wstring, BlockType> &types)
        : blockAppList(appList), blockTypes(types)
    {}

    ~BlockTypeDetector() = default;

    BlockType Detect(const ProcessInfo &process);

private:
    std::vector<AppInfo> blockAppList = {};
    std::map<std::wstring, BlockType> blockTypes;
};

class CustomFilter : public Filter {
public:
    explicit CustomFilter();

    explicit CustomFilter(
        const std::vector<AppInfo> &blockAppList, const std::map<std::wstring, BlockType> &blockTypes);

    ~CustomFilter() override;

    bool Handle(const ProcessInfo &process) override;

    bool BlockHandle(const BlockType &type, const ProcessInfo &process);

    void Update() override;

private:
    LRUCache<std::wstring> cache{128};  // 128: 已授权记录缓存
    std::unique_ptr<BlockTypeDetector> detector{nullptr};
    std::mutex lock{};
};

#endif
